import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';

import { FormItemBase } from '../../domain/form/form-item-base';

@Component({
  selector: 'app-form-item',
  templateUrl: './dynamic-form-item.component.html',
  styleUrls: ['./dynamic-form-item.component.scss'],
})
export class DynamicFormItemComponent implements OnInit {
  @Input() formItem: FormItemBase<string>;
  @Input() form: FormGroup;

  cn: any;

  get isValid() {
    // console.log(this.form.controls[this.formItem.key]);
    return this.form.controls[this.formItem.key].valid;
  }

  ngOnInit(): void {
    //  console.log(this.formItem);

    this.cn = {
      firstDayOfWeek: 0,
      dayNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
      monthNames: [
        '一月',
        '二月',
        '三月',
        '四月',
        '五月',
        '六月',
        '七月',
        '八月',
        '九月',
        '十月',
        '十一月',
        '十二月',
      ],
      monthNamesShort: [
        '一月',
        '二月',
        '三月',
        '四月',
        '五月',
        '六月',
        '七月',
        '八月',
        '九月',
        '十月',
        '十一月',
        '十二月',
      ],
      today: '今天',
      clear: '清空',
      dateFormat: 'mm/dd/yy',
      weekHeader: '周',
    };
  }

  get name() {
    // console.log(this.form.controls[this.formItem.key]);
    return this.form.controls[this.formItem.key];
  }
}
